//电影前台service
const movie_name = "_movie"

export default {
    create: (data) => new Promise(resolve => {
        $.ajax({
            url: "/api/movies/create",
            type: "POST",
            data,
            success: (data) => resolve(data)
        })
    }),
    get: () => new Promise(resolve => {
        $.ajax({
            url: "/api/movies",
            type: "GET",
            success: (data) =>{
                resolve(data)}
        })
    }),
    delete: (data) => new Promise(resolve => {
        $.ajax({
            url: "/api/movies/delete",
            type: "POST",
            data,
            success: (data) => resolve(data)//data : {ok: 1, n: 1, deletedCount: 1}
        })
    }),
    deleteMovieImg:(_id,src)=> new Promise(resolve => {
        $.ajax({
            url: `/movies/${_id}`,
            type: "PATCH",
            data:{
                $pull:JSON.stringify(src)
            },
            success: (data) =>resolve(data)
        })
    }),
    update: (data) => new Promise(resolve => {
        $.ajax({
            url: `/api/movies/${data._id}`,
            type: "PATCH",
            data,
            success:(data) => resolve(data)
        })
    }),
    setMovie:(movie)=>{
        localStorage[movie_name]=JSON.stringify(movie);
    },
    getMovie:()=> JSON.parse(localStorage[movie_name])
}